package Test;

import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        //得到分数的数组
        int[] scoreArr =getScore();
        //求最大值
        int max=getMax(scoreArr);
        //求最小值
        int min=getMin(scoreArr);
        //求总和
        int sum=getSum(scoreArr);
        //求平均数
        int avg=(sum-min-max)/(scoreArr.length-2);
        System.out.println("最后平均数为"+avg);
    }

    //求分数的数组
    public static int[] getScore() {
        //6个分数
        int[] scores = new int[6];
        //输入分数
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; ) {
            System.out.println("输入分数：");
            int score = sc.nextInt();
            if (score <= 100 && score >= 0) {
                scores[i] = score;
                i++;
            }else{
                System.out.println("输入错误，重新输入");
            }
        }
        return scores;
    }

    //求最小值
    public static int getMin(int[] arr){
        int min=arr[0];
        for (int i = 0; i < arr.length; i++) {
            if(min>arr[i]){
                min=arr[i];
            }
        }
        return min;
    }

    //求最大值
    public static int getMax(int[] arr){
        int max =arr[0];
        for (int i = 0; i < arr.length; i++) {
            if(max >arr[i]){
                max =arr[i];
            }
        }
        return max;
    }

    //求总和
    public static int getSum(int[] arr){
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        return sum;
    }
}
